package com.jobpass.swagger;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.VendorExtension;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@Configuration  //声明该类为配置类
@EnableSwagger2 //声明启动Swagger2
public class SwaggerConfig {
    @Value("${swagger.enable}")
    private Boolean enable;
    //配置Swagger的Docket的Bean实例
    @Bean
    public Docket docket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("Company的API接口文档")
                .apiInfo(apiInfo())
                .enable (enable) //是否启动Swagger，如果false，浏览器中无法访问
                .select()
                .apis(RequestHandlerSelectors.basePackage ("com.jobpass.controller"))//指向自己的controller即可
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfo("CodeHuan-Company的Api测试接口",
                "工欲善其事，必先利其器",
                "v1.0",
                "http://www.baidu.com",
                //作者信息
                new Contact("CodeHuan", "https://www.cnblogs.com/codehuan", "1730272469@qq.com"),
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList<VendorExtension>());
    }
}
